﻿// ==================================================================================================
// Copyright(C) 2013 NCS Pte. Ltd. All rights reserved.
//
// SYSTEM NAME	    : iConnect .Net Application Framework
// COMPONENT ID	    : NCS.IConnect.Core.WebApi
// COMPONENT DESC   : Expose iConnect.Net core functionality as web api.
//
// CREATED DATE/BY  : 23 April 2014 / Jiang Jin Nan
//
// REVISION HISTORY :	
// DATE/BY			SR#/CS/PM#/OTHERS		DESCRIPTION OF CHANGE
// ==================================================================================================

using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Web.Http;
using System.Web.Http.Cors;
using NCS.IConnect.Core.WebApi.Authorization;
using NCS.IConnect.Core.WebApi.Description;
using System.Runtime.InteropServices;

namespace NCS.IConnect.Core.WebApi
{
    /// <summary>The <see cref="ApiController" /> to retrieve and maintain cultures.</summary>
    [RoutePrefix("cultures")]
    [EnableCors("*", "*", "*")]
    [EnsureValidInput]
    [BuiltInApi]
    [ComVisible(false)]
    public class CulturesController : ApiControllerBase
    {
        /// <summary>
        ///     Get cultures on the server.
        /// </summary>
        /// <returns></returns>
        [Route("")]
        [Response(HttpStatusCode.OK, ResponseScenarios.Culture.SuccessfullyRetrieveCultures, typeof(CultureItem[]))]
        public IHttpActionResult Get()
        {
            var allCultures = CultureInfo.GetCultures(CultureTypes.AllCultures).OrderBy(it => it.Name);
            var result = allCultures.Select(
                it =>
                    new CultureItem
                    {
                        Lcid = it.LCID,
                        Name = it.Name,
                        NativeName = it.NativeName,
                        DisplayName = it.DisplayName,
                        EnglishName = it.EnglishName
                    });

            return Content(HttpStatusCode.OK, result);
        }
    }
}